﻿using System.Web.Mvc;
using DotNetNuke.Services.Social.Messaging.Internal;
using DotNetNuke.Services.Social.Notifications;
using DotNetNuke.Web.Services;

namespace MessageCenterAlerts.API
{
    public class CountsController : DnnController
    {
        [DnnAuthorize(AllowAnonymous = false, RequiresHost = false)]
        [SupportedModules("MessageCenterAlerts")]
        public ActionResult Get()
        {
            object result;

            if(!Request.IsAuthenticated)
            {
                result = new { success = false };
            }
            else
            {
                result = new
                {
                    success = true,
                    counts = new
                    {
                        notificationCount = NotificationsController.Instance.CountNotifications(UserInfo.UserID, PortalSettings.PortalId),
                        messageCount = InternalMessagingController.Instance.CountUnreadMessages(UserInfo.UserID, PortalSettings.PortalId)
                    }
                };
            }

            return Json(result, JsonRequestBehavior.AllowGet);
        }
    }
}